<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // if
        var count = 4;
        var unitPrice = 80;
        var totalPrice = 0;
        if (count == 1) {
            totalPrice = unitPrice * count * 0.9;
        } else if (count == 2) {
            totalPrice = unitPrice * count * 0.8;
        } else if (count == 3) {
            totalPrice = unitPrice * count * 0.7;
        } else {
            totalPrice = unitPrice * count * 0.5;
        }
        console.log("totalPrice=" + totalPrice);

        // switch
        switch (count) {
            case 1:
                totalPrice = unitPrice * count * 0.9;
                break;
            case 2:
                totalPrice = unitPrice * count * 0.8;
                break;
            case 3:
                totalPrice = unitPrice * count * 0.7;
                break;
            default:
                totalPrice = unitPrice * count * 0.5;
                break;
        }
        console.log("totalPrice=" + totalPrice);

        // while
        var i = 0;
        var sum1 = 0;
        while (i < 10) {
            sum1 += i; // sum1 = sum1+i;
            i++;
        }
        console.log("sum1=" + sum1);

        // do while
        var j = 0;
        var sum2 = 0;
        do {
            sum2 += j;
            j++;
        } while (j < 10)
        console.log("sum2=" + sum2);

        // for
        var k = 0;
        var sum3 = 0;
        for (k = 0; k < 10; k++) {
            sum3 += k;
        }
        console.log("sum3=" + sum3);

        // 定义数组
        var names = new Array(3);
        names[0] = "Jack";
        names[1] = "Steve";
        names[2] = "Tom";
        // for 循环遍历数组,names.length 表示数组的长度
        for (var m = 0; m < names.length; m++) {
            console.log(names[m]);
        }

        //  continue 跳过当前循环，继续完成后续的循环
        var p = 0;
        var sum4 = 0;
        for (p = 0; p < 10; p++) {
            if (p % 2 == 0) {
                continue;
            }
            sum4 += p;
        }
        console.log("sum4=" + sum4);

        // break 退出循环
        var h = 0;
        var sum5 = 0;
        for (h = 0; h < 10; h++) {
            if (h == 2) {
                break;
            }
            sum5 += h;
        }
        console.log("sum5=" + sum5);
    </script>
</body>

</html>